﻿using ConfExpert.Forms.Base;
using DevExpress.XtraGrid.Views.BandedGrid;
using Extensions;
using System;


namespace ITaskManager.Forms.IT
{
    public partial class DenormalizeFatura : XForm
    {
        public DenormalizeFatura()
        {
            InitializeComponent();
        }

        private void DenormalizationFatura_Load(object sender, EventArgs e)
        {
            gvDenormalizationFatura.Init("IT_GetDenormalizationFatura");
            InitBands();
            gvDenormalizationFatura.MakeReadOnly("UrunAdi","KullanimAmaci","Adet","BirimFiyat");
           
            
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gvDenormalizationFatura.DoubleClick += gvDenormalizationFatura_DoubleClick;
            gvDenormalizationFatura.BestFitColumns();
        }

        void gvDenormalizationFatura_DoubleClick(object sender, EventArgs e)
        {
           
            //DenormalizationFaturaDuzenle(BandedGridView.);
        }

        //private void DenormalizationFaturaDuzenle()
        //{
           
        //}


        private void InitBands()
        {
            gvDenormalizationFatura.Bands.Clear();

            AddBand("Faturalar", "SirketId,Tarih,FaturaNo,IT_FaturaTipiId,TedarikciId,Aciklama,Iskonto,KDVOrani");
            AddBand("Fatura Kalemleri", "UrunAdi,KullanimAmaci,Adet,BirimFiyat");


            foreach (DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn gc in gvDenormalizationFatura.Columns)
            {
                if (!gc.Visible || gc.OwnerBand == null)
                    gc.OptionsColumn.ShowInCustomizationForm = false;
            }

            //gvDenormalizationFatura.Images = bgvIcons;
            //gvDenormalizationFatura.ColumnPanelRowHeight = 28;
            //gvDenormalizationFatura.Appearance.HeaderPanel.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
            //gvDenormalizationFatura.Appearance.HeaderPanel.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center;

        }

        private void AddBand(string bandName, string columns)
        {
            GridBand band = gvDenormalizationFatura.Bands.AddBand(bandName);
            band.ImageIndex = (gvDenormalizationFatura.Bands.Count - 1) % 6;
            foreach (string colName in columns.Split(','))
            {
                BandedGridColumn gc = (BandedGridColumn)gvDenormalizationFatura.Columns[colName];
                band.Columns.Add(gc);
                gc.Visible = true;
            }
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvDenormalizationFatura.EndEdit();
            gvDenormalizationFatura.Update("","IT_FaturaLines");
            gvDenormalizationFatura.VeriyiGuncelle("IT_GetDenormalizationFatura");

        }



        //public object bgvIcons { get; set; }
    }
}
